package com.wll.ec.fast.database;

import android.content.Context;

import com.wll.ec.fast.database.greendao.DaoMaster;
import com.wll.ec.fast.database.greendao.DaoSession;
import com.wll.ec.fast.database.greendao.UserProfileDao;

import org.greenrobot.greendao.database.Database;

/**
 * Created by detachment on 2020/3/17
 */
public class DatabaseManager {

    private DaoSession mDaoSession = null;
    private UserProfileDao mUserProfileDao = null;

    private static final class Holder{
        private static final DatabaseManager INSTANCE = new DatabaseManager();
    }

    public static DatabaseManager getInstance(){
        return Holder.INSTANCE;
    }

    private DatabaseManager(){
    }

    public DatabaseManager init(Context context){
        initDao(context);
        return this;
    }

    private void initDao(Context context){
        final ReleaseOpenHelper helper = new ReleaseOpenHelper(context,"ec.db");
        final Database database = helper.getWritableDb();
        mDaoSession = new DaoMaster(database).newSession();
        mUserProfileDao = mDaoSession.getUserProfileDao();
    }

    public final UserProfileDao getUserProfileDao(){
        return mUserProfileDao;
    }

}
